package com.dd.keel.core.jclext;

import java.io.Serializable;
import org.apache.commons.logging.Log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Common log implement using SLF4J 
 * @author Kevin.XU
 *
 */
public class SLF4JLogger implements Log, Serializable{
	
	private static final long serialVersionUID = -2027351937930359364L;

	/** Log to this logger */
    private transient Logger logger = null;
	
    /** Logger name */
    private String name = null;
    

    public SLF4JLogger() {
    }

    /**
     * Base constructor.
     */
    public SLF4JLogger(String name) {
        this.name = name;
    }

    /** 
     * For use with a log4j factory.
     */
    public SLF4JLogger(Logger logger) {
        if (logger == null) {
            throw new IllegalArgumentException(
                "Warning - null logger in constructor; possible slf4j misconfiguration.");
        }
        this.name = logger.getName();
        this.logger=logger;
    }    
    
    /**
     * Return the native Logger instance we are using.
     */
    public Logger getLogger() {
        if (logger == null) {
            logger = LoggerFactory.getLogger(name);
        }
        return this.logger;
    }
    
	@Override
	public void debug(Object arg0) {
		getLogger().debug("{}",arg0);
	}

	@Override
	public void debug(Object arg0, Throwable arg1) {
		getLogger().debug((String)arg0, arg1);
	}

	@Override
	public void error(Object arg0) {
		getLogger().error("{}",arg0);
	}

	@Override
	public void error(Object arg0, Throwable arg1) {
		getLogger().error((String)arg0, arg1);
	}

	@Override
	public void fatal(Object arg0) {
		getLogger().error("{}",arg0);
	}

	@Override
	public void fatal(Object arg0, Throwable arg1) {
		getLogger().error((String)arg0, arg1);
	}

	@Override
	public void info(Object arg0) {
		getLogger().info("{}",arg0);
	}

	@Override
	public void info(Object arg0, Throwable arg1) {
		getLogger().info((String)arg0, arg1);
	}

	@Override
	public boolean isDebugEnabled() {
		return getLogger().isDebugEnabled();
	}

	@Override
	public boolean isErrorEnabled() {
		return getLogger().isErrorEnabled();
	}

	@Override
	public boolean isFatalEnabled() {
		return getLogger().isErrorEnabled();
	}

	@Override
	public boolean isInfoEnabled() {
		return getLogger().isInfoEnabled();
	}

	@Override
	public boolean isTraceEnabled() {
		return getLogger().isTraceEnabled();
	}

	@Override
	public boolean isWarnEnabled() {
		return getLogger().isWarnEnabled();
	}

	@Override
	public void trace(Object arg0) {
		getLogger().trace("{}",arg0);
	}

	@Override
	public void trace(Object arg0, Throwable arg1) {
		getLogger().trace((String)arg0, arg1);
	}

	@Override
	public void warn(Object arg0) {
		getLogger().warn("{}",arg0);
	}

	@Override
	public void warn(Object arg0, Throwable arg1) {
		getLogger().warn((String)arg0, arg1);
	}

}
